//#include "myHead.h"
#include "Board64_2.h"
#include <math.h>
struct Glpoint
{
	GLint x;
	GLint y;
};
struct Glcolor
{
	GLfloat r;
	GLfloat g;
	GLfloat b;
	GLfloat a;
};
static const GLint MY_SIZE = 60;
static const Glcolor one = {1.0,0.0,0.0,1.0};
static const Glcolor two = { 0.0, 1.0, 0.0, 1.0 };
static const GLint MAX_ROW = 8;
static const GLint MAX_COL = 8;
static GLboolean needChange = false;


void Board64_2::render()
{
	glClear(GL_COLOR_BUFFER_BIT);
	// create one row every time and accumulate like stack from bottom to top
	GLint currentRow = 0;
	//GLint currentCol = 0;
	GLint x1, y1, x2, y2;

	printf("++++++++++++++++++\n");
	for ( currentRow ; currentRow< MAX_ROW; currentRow++)
	{
		y1 = MY_SIZE*currentRow;
		printf("y1 is %d\n", y1);
		//printf("now row is %d,col is %d \n", currentRow, currentCol);
		for (GLint currentCol=0; currentCol < MAX_COL;currentCol++)
		{
			x1 = MY_SIZE*currentCol;
			
			x2 = x1 + MY_SIZE;
			y2 = y1 + MY_SIZE;
			printf("now x1 is %d,y1 is %d \n", x1, y1);
			renderBoard(x1, y1, x2, y2);
			needChange = ~needChange;
		
		}
		needChange = ~needChange; //new row should change the color too
	}
	//glutSwapBuffers();
	glFlush();
}
void Board64_2::renderBoard(GLint x1, GLint y1, GLint x2, GLint y2)
{	
	if (needChange)
	{
		glColor3f(one.r, one.g, one.b);
	}
	else
	{
		glColor3f(two.r, two.g, two.b);
	}
	glRecti(x1, y1, x2, y2);

}